package github.kawaiior.yuanchuxiuzhen.core.registry;

import github.kawaiior.yuanchuxiuzhen.core.init.EffectInit;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.DamageSource;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
public class RegisterPotion {
    @SubscribeEvent
    public static void onLivingHurt(LivingHurtEvent event){
        LivingEntity living = event.getEntityLiving();
        DamageSource source = event.getSource();

        if (living.isPotionActive(EffectInit.FALL_IMMUNITY_EFFECT.get()) && source==DamageSource.FALL){
            event.setAmount(0);
            event.setCanceled(true);
            return;
        }

        if (living.isPotionActive(EffectInit.LIGHTNING_RESISTANCE_EFFECT.get()) && source==DamageSource.LIGHTNING_BOLT){
            event.setAmount(event.getAmount()*0.5F);
            return;
        }
    }
}
